package com.rysima.wujiansima.demo.demo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*
(1)定义一个学生类Student，包含属性：姓名(String name)、年龄(int age)
(2)定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址)作为value
(3)利用四种方式遍历Map集合中的内容，格式：key::value
 */
public class HomeWork1 {
    public static void main(String[] args) {
        Map<Student,String> map = new HashMap<>();
        map.put(new Student("胡涵",26),"上海");
        map.put(new Student("物件",23),"湖南");
        map.put(new Student("任意",26),"北京");
//        第一种 entry map
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "::" + value);
        }
        System.out.println("======================");
//        第二种 map.get
        Set<Student> students = map.keySet();
        for (Student student : students) {
            String s = map.get(student);
            System.out.println(student + "::" + s);
        }
        System.out.println("======================");
//        第三种 迭代器
        Set<Map.Entry<Student, String>> set = map.entrySet();
        Iterator<Map.Entry<Student, String>> iterator = set.iterator();
        while(iterator.hasNext()){
            Map.Entry<Student, String> next = iterator.next();
            System.out.println(next.getKey() + "::" + next.getValue());
        }
        System.out.println("=======================");
//        第四种
        Set<Map.Entry<Student, String>> set1 = map.entrySet();


    }
}
